package com.manage.project.biz.controller;

import java.util.List;

import com.manage.common.utils.DateUtils;
import com.manage.project.biz.domain.BizTujianjiegoujishupingding1;
import com.manage.project.biz.service.IBizTujianjiegoujishupingding1Service;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizTujianjiegoujishupingding;
import com.manage.project.biz.service.IBizTujianjiegoujishupingdingService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 Controller
 *
 * @author liutao
 *
 */
@RestController
@RequestMapping("/biz/tujianjiegoujishupingding")
public class BizTujianjiegoujishupingdingController extends BaseController
{
    @Autowired
    private IBizTujianjiegoujishupingdingService bizTujianjiegoujishupingdingService;
    @Autowired
    private IBizTujianjiegoujishupingding1Service bizTujianjiegoujishupingding1Service;

    /**
     * 查询土建结构技术评定记录列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:tujianjiegoujishupingding:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTujianjiegoujishupingding bizTujianjiegoujishupingding)
    {
        startPage();
        List<BizTujianjiegoujishupingding> list = bizTujianjiegoujishupingdingService.selectBizTujianjiegoujishupingdingList(bizTujianjiegoujishupingding);
        return getDataTable(list);
    }

    /**
     * 导出土建结构技术评定记录列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:tujianjiegoujishupingding:export')")
    @Log(title = "土建结构技术评定记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizTujianjiegoujishupingding bizTujianjiegoujishupingding)
    {
        List<BizTujianjiegoujishupingding> list = bizTujianjiegoujishupingdingService.selectBizTujianjiegoujishupingdingList(bizTujianjiegoujishupingding);
        ExcelUtil<BizTujianjiegoujishupingding> util = new ExcelUtil<BizTujianjiegoujishupingding>(BizTujianjiegoujishupingding.class);
        return util.exportExcel(list, "土建结构技术评定记录数据");
    }

    /**
     * 获取土建结构技术评定记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:tujianjiegoujishupingding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizTujianjiegoujishupingdingService.selectBizTujianjiegoujishupingdingById(id));
    }

    /**
     * 新增土建结构技术评定记录
     */
//    @PreAuthorize("@ss.hasPermi('biz:tujianjiegoujishupingding:add')")
    @Log(title = "土建结构技术评定记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTujianjiegoujishupingding bizTujianjiegoujishupingding)
    {
        //查询个分项
        BizTujianjiegoujishupingding1 bizTujianjiegoujishupingding1 = new BizTujianjiegoujishupingding1();
        bizTujianjiegoujishupingding1.setField2(bizTujianjiegoujishupingding.getField2());
        List<BizTujianjiegoujishupingding1>  bizTujianjiegoujishupingding1List = bizTujianjiegoujishupingding1Service.selectBizTujianjiegoujishupingding1List(bizTujianjiegoujishupingding1);
        //总权重值
        Integer tol =0;
        for (BizTujianjiegoujishupingding1 tujianjiegoujishupingding1 : bizTujianjiegoujishupingding1List) {
            if(tujianjiegoujishupingding1.getField4().equals("洞口")){ tol+=15;}
            else if (tujianjiegoujishupingding1.getField4().equals("洞门")){tol+=5;}
            else if (tujianjiegoujishupingding1.getField4().equals("衬砌-结构破损")){tol+=40;}
            else if (tujianjiegoujishupingding1.getField4().equals("衬砌-渗透水")){tol+=40;}
            else if (tujianjiegoujishupingding1.getField4().equals("路面")){tol+=15;}
            else if (tujianjiegoujishupingding1.getField4().equals("检修道")){tol+=2;}
            else if (tujianjiegoujishupingding1.getField4().equals("排水设施")){tol+=6;}
            else if (tujianjiegoujishupingding1.getField4().equals("吊顶及预埋件")){tol+=10;}
            else if (tujianjiegoujishupingding1.getField4().equals("内装饰")){tol+=2;}
            else if (tujianjiegoujishupingding1.getField4().equals("交通标志、标线")){tol+=5;}
        }
        //总得分
        float zdf = 0;
        for (BizTujianjiegoujishupingding1 tujianjiegoujishupingding1 : bizTujianjiegoujishupingding1List) {
            //各项得分
            Integer df = 0;
            if(tujianjiegoujishupingding1.getField4().equals("洞口")){ df=15;}
            else if (tujianjiegoujishupingding1.getField4().equals("洞门")){df=5;}
            else if (tujianjiegoujishupingding1.getField4().equals("衬砌-结构破损")){df=40;}
            else if (tujianjiegoujishupingding1.getField4().equals("衬砌-渗透水")){df=40;}
            else if (tujianjiegoujishupingding1.getField4().equals("路面")){df=15;}
            else if (tujianjiegoujishupingding1.getField4().equals("检修道")){df=2;}
            else if (tujianjiegoujishupingding1.getField4().equals("排水设施")){df=6;}
            else if (tujianjiegoujishupingding1.getField4().equals("吊顶及预埋件")){df=10;}
            else if (tujianjiegoujishupingding1.getField4().equals("内装饰")){df=2;}
            else if (tujianjiegoujishupingding1.getField4().equals("交通标志、标线")){df=5;}
            //累计得分
            zdf+= Float.valueOf(tujianjiegoujishupingding1.getField5())*(df/tol);
        }
        //计算结果
        float jg = 100*(1-zdf/4);
        String lev= "无";
        if(jg>=85){lev ="1类";}else if (jg>=70 && jg <85){lev = "2类";}else if(jg>=55 && jg <70){lev="3类";}else if(jg>=40 && jg <55){lev ="4类";}else if(jg<40){lev="5类";}
        bizTujianjiegoujishupingding.setField9(lev);

        BizTujianjiegoujishupingding bizTujianjiegoujishupingding2 = new BizTujianjiegoujishupingding();
        bizTujianjiegoujishupingding2.setField2(bizTujianjiegoujishupingding.getField2());
        List<BizTujianjiegoujishupingding> bizTujianjiegoujishupingdingList = bizTujianjiegoujishupingdingService.selectBizTujianjiegoujishupingdingList(bizTujianjiegoujishupingding2);
        bizTujianjiegoujishupingding.setField5("无");
        bizTujianjiegoujishupingding.setField6("无");
        if(bizTujianjiegoujishupingdingList.size()>0){
            bizTujianjiegoujishupingding.setField5(bizTujianjiegoujishupingdingList.get(0).getField9());
            bizTujianjiegoujishupingding.setField6(bizTujianjiegoujishupingdingList.get(0).getField10());
        }
        bizTujianjiegoujishupingding.setField10(DateUtils.getTime());
        return toAjax(bizTujianjiegoujishupingdingService.insertBizTujianjiegoujishupingding(bizTujianjiegoujishupingding));
    }

    /**
     * 修改土建结构技术评定记录
     */
    @Log(title = "土建结构技术评定记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTujianjiegoujishupingding bizTujianjiegoujishupingding)
    {
        return toAjax(bizTujianjiegoujishupingdingService.updateBizTujianjiegoujishupingding(bizTujianjiegoujishupingding));
    }

    /**
     * 删除土建结构技术评定记录
     */
//    @PreAuthorize("@ss.hasPermi('biz:tujianjiegoujishupingding:remove')")
    @Log(title = "土建结构技术评定记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizTujianjiegoujishupingdingService.deleteBizTujianjiegoujishupingdingByIds(ids));
    }
}
